import {Service} from "adajs";

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                "id": "",
                "title": "",
                "dzbid": "",
                "crtUser": "",
                "crtTime": "",
                "nr": "",
                "fjid": ""
            },
            id: "",
            error: false,
            msg: ""
        };
    }

    onupdate(current, id) {
        if (id) {
            return this.context.request.get("/api/cms/cmsArticle/get", {id}).then(({data, code, msg}) => {
                current.id = id;
                current.isLoad = true;
                if (code === '1') {
                    current.newsInfo = data;
                } else {
                    current.error = true;
                    current.msg = msg;
                }
            });
        }
    }
}

export default NewsService;